package com.ruoyi.vipPrice.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.vipPrice.domain.VipPrices;
import com.ruoyi.vipPrice.service.IVipPricesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员价格Controller
 * 
 * @author ruoyi
 * @date 2024-11-09
 */
@RestController
@RequestMapping("/vipPrice/vipPrice")
public class VipPricesController extends BaseController
{
    @Autowired
    private IVipPricesService vipPricesService;

    /**
     * 查询会员价格列表
     */
    @PreAuthorize("@ss.hasPermi('vipPrice:vipPrice:list')")
    @GetMapping("/list")
    public TableDataInfo list(VipPrices vipPrices)
    {
        startPage();
        List<VipPrices> list = vipPricesService.selectVipPricesList(vipPrices);
        return getDataTable(list);
    }

    /**
     * 导出会员价格列表
     */
    @PreAuthorize("@ss.hasPermi('vipPrice:vipPrice:export')")
    @Log(title = "会员价格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VipPrices vipPrices)
    {
        List<VipPrices> list = vipPricesService.selectVipPricesList(vipPrices);
        ExcelUtil<VipPrices> util = new ExcelUtil<VipPrices>(VipPrices.class);
        util.exportExcel(response, list, "会员价格数据");
    }

    /**
     * 获取会员价格详细信息
     */
    @PreAuthorize("@ss.hasPermi('vipPrice:vipPrice:query')")
    @GetMapping(value = "/{priceId}")
    public AjaxResult getInfo(@PathVariable("priceId") Long priceId)
    {
        return success(vipPricesService.selectVipPricesByPriceId(priceId));
    }

    /**
     * 新增会员价格
     */
    @PreAuthorize("@ss.hasPermi('vipPrice:vipPrice:add')")
    @Log(title = "会员价格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VipPrices vipPrices)
    {
        int rows = vipPricesService.insertVipPrices(vipPrices);
        if (rows == 0){
            return error("已存在对应的会员设置");
        }else{
            return success();
        }
    }

    /**
     * 修改会员价格
     */
    @PreAuthorize("@ss.hasPermi('vipPrice:vipPrice:edit')")
    @Log(title = "会员价格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VipPrices vipPrices)
    {
        int rows = vipPricesService.updateVipPrices(vipPrices);
        if (rows == 0){
            return error("已存在对应的会员设置");
        }else{
            return success();
        }
    }

    /**
     * 删除会员价格
     */
    @PreAuthorize("@ss.hasPermi('vipPrice:vipPrice:remove')")
    @Log(title = "会员价格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{priceIds}")
    public AjaxResult remove(@PathVariable Long[] priceIds)
    {
        return toAjax(vipPricesService.deleteVipPricesByPriceIds(priceIds));
    }
}
